  //
  //  Migration.swift
  //  hello
  //
  //  Created by 赵康 on 2025/3/24.
  //


import Fluent

extension Feedback {
  struct Migration: AsyncMigration {
    var name: String { "FeedbackMigration" }
    
    func prepare(on database: any Database) async throws {
      try await database.schema(Feedback.schema)
        .id()
        .field(Feedback.FieldKeys.reporter, .uuid, .required, .references(User.schema, .id))
        .field(Feedback.FieldKeys.category, .string, .required)
        .field(Feedback.FieldKeys.type, .string, .required)
        .field(Feedback.FieldKeys.content, .string)
        .field(Feedback.FieldKeys.status, .string, .required)
        .field(Feedback.FieldKeys.audio, .uuid, .references(Audio.schema, .id))
        .field(Feedback.FieldKeys.transcript, .uuid, .references(Transcript.schema, .id))
        .field(Feedback.FieldKeys.note, .uuid, .references(Note.schema, .id))
        .field(Feedback.FieldKeys.createdAt, .datetime)
        .field(Feedback.FieldKeys.updatedAt, .datetime)
        .create()
    }
    
    func revert(on database: any Database) async throws {
      try await database.schema(Feedback.schema).delete()
    }
  }
}
